local huilie = fk.CreateSkill {
  name = "huilie",
  tags={Skill.Wake}
}

huilie:addEffect(fk.EventPhaseStart, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and
      player.phase == Player.Start and
      player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  can_wake = function(self, event, target, player, data)
    return #table.filter(player.room.alive_players, function (p) return p:getMark("@@caocao_lie") > 0 end) > 2
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player, -1)
    if not player.dead then
      room:handleAddLoseSkills(player, "pingrong|jsrg_feiying", nil)
    end
  end,
})

huilie:addTest(function(room, me)
  local comp2=room.players[2]
  local comp3=room.players[3]
  local comp4=room.players[4]

  FkTest.runInRoom(function()
    room:handleAddLoseSkills(me, "huilie")
    room:addPlayerMark(comp2,"@@caocao_lie")
    room:addPlayerMark(comp3,"@@caocao_lie")
  end)

  FkTest.setNextReplies(me, { "" })
  FkTest.runInRoom(function()
    local data = { ---@type TurnDataSpec
      who = me,
      reason = "game_rule",
      phase_table = { Player.Start }
    }
    GameEvent.Turn:create(TurnData:new(data)):exec()
  end)

  lu.assertEquals(me:hasSkill("pingrong"), true)
  lu.assertEquals(me:hasSkill("jsrg_feiying"), true)
  lu.assertEquals(me.maxHp, 3)

end)
return huilie
